package com.iflytek.sbd.demo.daili.dongtaidaili.cglib;
import org.springframework.cglib.proxy.Enhancer;

/**
 * @program: sbd
 * @description:
 * @author: 陈英俊
 * @create: 2022-01-04 16:42
 */
public class Demo {


    public static void main(String[] args) {
        //代理类class文件存入本地磁盘方便我们反编译查看源码
       // System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "F:\\workspace\\demo");
        //通过CGLIB动态代理获取代理对象的过程
        Enhancer enhancer = new Enhancer();
        //设置enhancer对象的父类
        enhancer.setSuperclass(ReallyService.class);
        //设置enhancer的回调对象
        enhancer.setCallback(new MyMethodInterceptor());
        //创建代理对象
        ReallyService proxy = (ReallyService) enhancer.create();
        //通过代理对象调用目标方法
        proxy.sayHello();
    }
}
